package se.energimyndigheten.lampguiden;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;

import se.energimyndigheten.lampguiden.R;

public class WebViewActivity extends SubPageActivity {

    public static final String EXTRA_HTML_PATH = "html_path";
    public static final String EXTRA_SECTION_ID = "section_id";

    private static final String TAG = WebViewActivity.class.getSimpleName();

    private String mPath;

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // check intent for html file path
        try {
            final Intent intent = getIntent();
            mPath = intent.getStringExtra(EXTRA_HTML_PATH);
            mSelectedActivity = intent.getIntExtra(EXTRA_SECTION_ID, -1);
        } catch (NullPointerException npe) {
            Log.e(TAG, "NullPointerException - invalid intent or missing required extra.");
            finish();
            return;
        }

        setContentView(R.layout.webview_activity);
        mWebView = (WebView) findViewById(R.id.webview);
        loadHtmlFile();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    private void loadHtmlFile() {
        String path = mPath != null ? mPath : "file::///android_asset/404.html";
        Log.v(TAG, "loadHtmlFile :: path: " + path);
        mWebView.loadUrl(path);
    }
}
